<?php

namespace App\Http\Controllers\Mapi;
use App\Http\Controllers\Controller;
use App\Http\Validators\BeatValidator;
use App\Services\BeatService;
use App\Services\CollectionService;
use App\Services\RhymeService;
use Illuminate\Http\Request;
use App\Api\Helper\ReturnMessage;
use Illuminate\Support\Facades\Cache;

class CollectionController extends Controller
{

    /**
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @name 收藏列表
     * @user IHammer
     */
    public function CollectionLists(Request $request){
        $type = $request->input('type');
        if(!in_array($type,['music','beat'])){
            return ReturnMessage::success('参数错误',1001);
        }
        $page = intval($request->input('page'))>0 ?$request->input('page'):1;
        $pageSize = intval($request->input('pageSize'))>0 ?$request->input('pageSize'):10;
        $lists = CollectionService::CollectionListsHandle($page,$pageSize,$type);
        return ReturnMessage::successArray($lists);
    }
    /**
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @name Beat 收藏
     * @user IHammer
     */
    public function CollectionBeatCreate(Request $request){
        $request->offsetSet("type",'beat');
        $request->offsetSet("user_id",constant('_USER_ID'));
        $errmsg = "操作失败";
        $res = CollectionService::CollectionCreateHandle($request,$errmsg);
        if($res){
            return ReturnMessage::success('操作成功');
        }
        return ReturnMessage::success($errmsg,1001);
    }

    /**
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @name Music 收藏
     * @user IHammer
     */
    public function CollectionMusicCreate(Request $request){
        $request->offsetSet("type",'music');
        $request->offsetSet("user_id",constant('_USER_ID'));
        $errmsg = "操作失败";
        $res = CollectionService::CollectionCreateHandle($request,$errmsg);
        if($res){
            return ReturnMessage::success('操作成功');
        }
        return ReturnMessage::success($errmsg,1001);
    }
    /**
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @name Beat 收藏
     * @user IHammer
     */
    public function CollectionBeatDelete(Request $request){
        $request->offsetSet("type",'beat');
        $request->offsetSet("user_id",constant('_USER_ID'));
        $errmsg = "操作失败";
        $res = CollectionService::CollectionDeleteHandle($request,$errmsg);
        if($res){
            return ReturnMessage::success('操作成功');
        }
        return ReturnMessage::success($errmsg,1001);
    }

    /**
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @name Music 收藏
     * @user IHammer
     */
    public function CollectionMusicDelete(Request $request){
        $request->offsetSet("type",'music');
        $request->offsetSet("user_id",constant('_USER_ID'));
        $errmsg = "操作失败";
        $res = CollectionService::CollectionDeleteHandle($request,$errmsg);
        if($res){
            return ReturnMessage::success('操作成功');
        }
        return ReturnMessage::success($errmsg,1001);
    }

}
